#!/bin/bash

red='\e[0;31m'
yellow='\e[1;33m'
green='\e[0;32m'
NC='\e[0m'
echo "Hi, I'm grace the POSIX compatible computer performance program!
"
sleep 4s;

echo "Lets see how much of space you have used..
"
SPACE=`df / --output=pcent |tail -1| tr -d ' ' | tr -d '%'`
echo "I'm going to look in your user directory for big files you haven't used in awhile. This should just take a second!
"
find ~ -atime +30 -size +10M -exec du  {} \; |sort -gr >> tmpfiles.txt

echo "Awesome, now I am going to look at some processes going on.
"
ps -axo pcpu,pid,user,args | sort -k 1 -r | head -6 >> tmpprocess.txt
echo "Alright, lets see how your processor is handling things right now. This will take 20 seconds
"
sar 1 20 >> tmpcpustat.txt
CPU=`tail -1 tmpcpustat.txt`
rm tmpcpustat.txt

echo "Now lets see your RAM usage
"
RAM=`free -h | head -n 2| tail -1`

echo "Alright, all tests done. Let's see the results
"

if [ "$SPACE" -ge 75 ]; then 
	echo -e "Woah, your disk usage is $SPACE%. We should trim that down. If your computer is slowing down, this might be the culprit.
DISK SPACE STATUS: ${red}BAD${NC}
"
elif  [ "$SPACE" -ge 50 ]; then
	echo -e "Alright. Your disk usage is about $SPACE%. That isn't too bad, but you should watch it.
DISK SPACE STATUS: ${yellow}ALRIGHT${NC}"
else
	echo -e "Wow! Your disk usage is only $SPACE%! It should not be affecting your performance
DISK SPACE STATUS: ${green}GOOD!${NC}
"
fi

echo "Alright now, for the results of the processor test..."

cat tmpprocess.txt;



#cat tmp.txt
rm tmpfiles.txt
rm tmpprocess.txt

